package com.platform.enums;

import com.platform.comm.enums.IDictEntry;
import com.platform.comm.enums.IEnumItem;

/**
 * 字段控件
 *
 * @author wxw
 * @date 2021-08-23
 */
public enum FieldControlType implements IDictEntry, IEnumItem {
    /**
     * 文本框
     */
    TEXT("文本框", "text"),
    /**
     * 增加数值文本框
     */
    NUMBER_TEXT("数值文本框", "numberText"),

    PASSWORD("密码框", "password"),
    RADIO("单选框", "radio"),
    CHECKBOX("复选框", "checkbox"),
    SELECT("下拉框", "select"),

    /**
     * 增加下划线分隔
     */
    COMBO_BOX("组合下拉框", "comboBox"),
    DATE("日期", "date"),

    /**
     * 增加日期时间类型，用于区分日期、日期和时间
     */
    DATE_TIME("日期时间", "datetime"),

    TEXTAREA("文本域", "textarea"),

    NAT_PERSON("选择自然人", "natPerson"),
    LEG_PERSON("选择法人", "legPerson"),

    /**
     * 增加行政区划和行业代码
     */
    REGION_SELECT("行政区划", "regionSelect"),
    HYDM_SELECT("行业代码", "hydmSelect"),

    FILE_UPLOAD("文件上传","fileUpload");

    public final String code;
    public final String title;

    FieldControlType(String title, String code) {
        this.title = title;
        this.code = code;
    }

    public static FieldControlType parse(String code) {
        if (code != null) {
            for (FieldControlType ctrl : values()) {
                if (ctrl.code.equals(code)) {
                    return ctrl;
                }
            }
        }
        return null;
    }

    @Override
    public boolean is(String code) {
        return this.code.equals(code);
    }

    @Override
    public String getKey() {
        return this.code;
    }

    @Override
    public String getValue() {
        return this.title;
    }

    @Override
    public Object getData() {
        return this;
    }

}
